package com.bzkj.msfx.service.impl.fileTransfer;


import com.alibaba.fastjson2.JSONObject;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.msfx.domain.fileTransfer.ErpSharefolders;
import com.bzkj.msfx.service.fileTransfer.ErpSharefoldersService;
import com.bzkj.msfx.utils.FusionHttpUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 共享文件夹配置Service业务层处理
 *
 * @author chj
 * @date 2024-01-08
 */
@Service
public class ErpSharefoldersServiceImpl implements ErpSharefoldersService {


    @Resource
    private FusionHttpUtils fusionHttpUtils;

    /**
     * 查询共享文件夹配置
     *
     * @param id 共享文件夹配置主键
     * @return 共享文件夹配置
     */

    @Override
    public AjaxResult selectErpSharefoldersById(Long id) {
        try {
            return fusionHttpUtils.sendGetRestFulApi("/fileTransfer/ShareFolders/" + id);
        } catch (Exception e) {
            return AjaxResult.error("查询共享文件夹配置失败，具体原因：" + e.getMessage());
        }
    }

    /**
     * 查询共享文件夹配置列表
     *
     * @param erpSharefolders 共享文件夹配置
     * @return 共享文件夹配置
     */
    @Override
    public TableDataInfo selectErpSharefoldersList(ErpSharefolders erpSharefolders) {
        return fusionHttpUtils.getTableDataInfo("/fileTransfer/ShareFolders/list", erpSharefolders);
    }

    /**
     * 新增共享文件夹配置
     *
     * @param erpSharefolders 共享文件夹配置
     * @return 结果
     */
    @Override
    public AjaxResult insertErpSharefolders(ErpSharefolders erpSharefolders) {
        try {
            return fusionHttpUtils.sendPostRequest("/fileTransfer/ShareFolders", null, JSONObject.toJSONString(erpSharefolders), "application/json");
        } catch (Exception e) {
            return AjaxResult.error("新增共享文件夹配置失败，具体原因：" + e.getMessage());
        }
    }

    /**
     * 修改共享文件夹配置
     *
     * @param erpSharefolders 共享文件夹配置
     * @return 结果
     */
    @Override
    public AjaxResult updateErpSharefolders(ErpSharefolders erpSharefolders) {
        try {
            return fusionHttpUtils.sendPut("/fileTransfer/ShareFolders", erpSharefolders);
        } catch (RuntimeException e) {
            return AjaxResult.error("修改共享文件夹配置失败，具体原因：" + e.getMessage());
        }
    }

    /**
     * 批量删除共享文件夹配置
     *
     * @param ids 需要删除的共享文件夹配置主键
     * @return 结果
     */
    @Override
    public AjaxResult deleteErpSharefoldersByIds(Long ids) {
        try {
            return fusionHttpUtils.sendDeleteRequest("/fileTransfer/ShareFolders/" + ids,null, null, null);
        } catch (Exception e) {
            return AjaxResult.error("删除共享文件夹配置失败，具体原因：" + e.getMessage());
        }

    }
}
